package com.example.forum.controller;


import com.example.forum.commons.jwt.JwtHelper;
import com.example.forum.commons.tools.Constants;
import com.example.forum.commons.tools.WebContextUtil;
import com.example.forum.vo.CurrentUser;
import org.springframework.beans.factory.annotation.Autowired;

public class BaseController {
    @Autowired
    private JwtHelper jwtHelper;

    public CurrentUser currentUser() {
        return jwtHelper.getJwtTokenResult(WebContextUtil.getRequest().getHeader(Constants.HEADER_STRING));
    }

    public String currentUserId() {
        try {
            return jwtHelper.getJwtTokenResult(WebContextUtil.getRequest().getHeader(Constants.HEADER_STRING)).getId();
        } catch (Exception e) {
            return "";
        }
    }
}
